﻿@using System.Data;
@using GatewayServer.Common;
@using UtilsBase;
@{
    ViewBag.PageTitle = "洪峰智能";

    Layout = "~/Views/Shared/PageTemplate.cshtml";
}

<script>
    $(document).ready(function () {

        if ("@(ViewBag.order)" == "upd") {
            getEdit("@(ViewBag.d_guid)");

        }

        getModelList();
    });


    function getEdit(dguid) {
        $.post("getDevice", { "flag": Math.random(), guid: dguid }, function (result) {
            var myobj = (result.data);
            $("#d_name").val(myobj.d_name);
            $("#d_remark").val(myobj.d_remark);
            $("#hid_d_model_guid").val(myobj.d_model_guid);
            for (var i = 0; i < document.getElementById("d_status").options.length; i++) {
                if (document.getElementById("d_status").options[i].value == myobj.d_status) {
                    document.getElementById("d_status").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("d_status").options[i].selected = false;

                }
            }
            getModelList();
        });

        $.post("getGateWay", { "flag": Math.random(), guid: dguid }, function (result) {
            var myobj = (result.data);
            $("#gw_system").val(myobj.gw_system);
      
        });
    }
    


    function getModelList() {
        $("#d_model_guid").empty();
        $("#d_model_guid").append("<option value=''  selected='selected'>请选择</option>");
        $.post("getModelList", { "flag": Math.random() }, function (result) {
            var myobj = (result.data);
            for (var i = myobj.length - 1; i >= 0; i--) {
                $("#d_model_guid").prepend("<option value='" + myobj[i].m_guid + "'>" + myobj[i].m_code + "-" + myobj[i].m_name + "</option>")
            }


            for (var i = 0; i < document.getElementById("d_model_guid").options.length; i++) {
                if (document.getElementById("d_model_guid").options[i].value == $("#hid_d_model_guid").val()) {
                    document.getElementById("d_model_guid").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("d_model_guid").options[i].selected = false;

                }
            }
        });
    }


    function saveAll() {
        var data = $("#addForm").serializeArray(); //自动将form表单封装成json
        $.post("saveGateWay", data, function (result) {
            var jsonresult = (result);
            if (jsonresult.respCode == "200") {
                window.location.href = "list?p_guid=" + $("#d_p_guid").val();
                // window.history.back();
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }
        });

    }
</script>

<style>
    #pagelist_follow {
        width: 100%;
    }

    #pagelist_main {
        width: 100%;
    }

    .kv-item label {
        width: 150px;
    }
</style>
<div id="saper-container">
    <form id="addForm" name="addForm" action="list" method="post">
        <input type="hidden" name="d_p_guid" id="d_p_guid" value="@ViewBag.d_p_guid" />
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>网关管理</h2>
            </div>
            <div class="subfiled-content">

                <div id="" title="添加/编辑">
                    <form action="" name="addForm" id="addForm" method="post">

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>名称：</label>
                            <div class="kv-item-content">
                                <input type="text" name="d_name" id="d_name" placeholder="名称" />
                                <input type="hidden" name="d_guid" id="d_guid" value="@ViewBag.d_guid" />
                            </div>
                        </div>

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>状态：</label>
                            <div class="kv-item-content">
                                <select id="d_status" name="d_status" style="width:130px;">
                                    <option value="0">启用</option>
                                    <option value="1">禁用</option>
                                </select>

                            </div>
                        </div>

                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>型号：</label>
                            <div class="kv-item-content">
                                <select id="d_model_guid" name="d_model_guid" style="width:130px;" onchange="checkShowGateWay(this.value)">
                                </select>
                                <input type="hidden" name="hid_d_model_guid" id="hid_d_model_guid" value="" />
                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>操作系统：</label>
                            <div class="kv-item-content">
                                <input type="text" name="gw_system" id="gw_system" placeholder="操作系统" />
                            </div>
                        </div>


                        <div class="kv-item clearfix">
                            <label><span class="impInfo"></span>备注：</label>
                            <div class="kv-item-content">
                                <input type="text" name="d_remark" id="d_remark" placeholder="备注" />
                            </div>
                        </div>

                     
                        <div><hr /></div>

                        <div><hr /></div>
                        <div style="margin:0 auto;width:150px;">

                            <input type="button" id="save" name="save" value="保存设备" onclick="javascript:saveAll()" />
                            &nbsp;&nbsp; <input type="button" id="but_back1" name="but_back1" value="返回" onclick="javascript:window.location.href='list?p_guid=@(Context.Request.Query["p_guid"])'" />
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div id="saper-ft"></div>
    </form>
</div>

